package com.kobe.algorithm.leetcode.case7;

/**
 * @author ：caopengfei
 * @date ：2021/3/7
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
//        System.out.println(Math.pow(2,31));
//        System.out.println(Integer.MAX_VALUE);
       System.out.println(solution.reverse(1534236469));
    }

    public int reverse(int x) {
        int num = 0;
        while(x != 0){
            int mod =  x%10;
            x = x/10;
            if (num > Integer.MAX_VALUE/10 || (num == Integer.MAX_VALUE / 10 && mod > 7)) {return 0;}
            if (num < Integer.MIN_VALUE/10 || (num == Integer.MIN_VALUE / 10 && mod < -8)) {return 0;}
            num = num*10 + mod;
        }
        return num;
    }
}
